﻿/* 
 * fileInput上传控件封装
 */
(function ($) {
    $.fn.fileInputSet = function (option) {
        /// <summary>
        /// 文件上传,基于fileInput控件
        /// </summary>
        /// <param name="option">配置项:<br/>
        /// uploadUrl上传地址;<br/>
        /// 用on方法绑定fileuploaded事件处理上传成功后的前台逻辑;<br/>
        /// 其他参数请参考fileInput官网：http://plugins.krajee.com/file-input ;<br/>
        ///</param>
        var opt = {
            uploadAsync: true,
            showCaption: false,
            showPreview: false,
            showRemove: false,
            showUpload: false,
            showCancel: false,
            showClose: false,
            showUploadedThumbs: false,
            //language: 'zh',
            layoutTemplates: { progress: "" }
        };
        $.extend(opt, option);
        return $(this).fileinput(opt)
        .on("filebatchselected", function (event, files) {
            $(this).fileinput("upload");
        });
    }
    $.fn.fileInputSet_Image = function (option) {
        /// <summary>
        /// 图片上传,基于fileInput控件
        /// </summary>
        /// <param name="option">配置项:<br/>
        /// uploadUrl上传地址;<br/>
        /// 用on方法绑定fileuploaded事件处理上传成功后的前台逻辑;<br/>
        /// 其他参数请参考fileInput官网：http://plugins.krajee.com/file-input ;<br/>
        ///</param>
        var opt = {
            allowedFileExtensions: ['bmp', 'jpg', 'png', 'gif', 'jpeg']
        };
        $.extend(opt, option);
        return $(this).fileInputSet(opt);
    }
    $.fn.fileInputSet_Excel = function (option) {
        /// <summary>
        /// Exccel上传,基于fileInput控件
        /// </summary>
        /// <param name="option">配置项:<br/>
        /// uploadUrl上传地址;<br/>
        /// 用on方法绑定fileuploaded事件处理上传成功后的前台逻辑;<br/>
        /// 其他参数请参考fileInput官网：http://plugins.krajee.com/file-input ;<br/>
        ///</param>
        var opt = {
            allowedFileExtensions: ['xls', 'xlsx']
        };
        $.extend(opt, option);
        return $(this).fileInputSet(opt);
    }
})(jQuery);